package ai.tubes.iris;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class KnowledgeEditorActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.knowedit);
		
		alertDialog = new AlertDialog.Builder(this).create();
		
		mesininferensi = new ai.tubes.iris.knowledge.inferenceengine();

		TableField = mesininferensi.getInferenceTable(); // untuk ngambil data
		
		laringbawah = (EditText) findViewById(R.id.txtlaringbawah);
		laringatas = (EditText) findViewById(R.id.txtlaringatas);
		tiroidbawah = (EditText) findViewById(R.id.txttiroidbawah);
		tiroidatas = (EditText) findViewById(R.id.txttiroidatas);
		bronkusbawah = (EditText) findViewById(R.id.txtbronkusbawah);
		bronkusatas = (EditText) findViewById(R.id.txtbronkusatas);
		appendiksbawah = (EditText) findViewById(R.id.txtappendiksbawah);
		appendiksatas = (EditText) findViewById(R.id.txtappendiksatas);
		pankreasbawah = (EditText) findViewById(R.id.txtpankreasbawah);
		pankreasatas = (EditText) findViewById(R.id.txtpankreasatas);
		hatibawah = (EditText) findViewById(R.id.txthatibawah);
		hatiatas = (EditText) findViewById(R.id.txthatiatas);
		empedubawah = (EditText) findViewById(R.id.txtempedubawah);
		empeduatas = (EditText) findViewById(R.id.txtempeduatas);
		ginjalbawah = (EditText) findViewById(R.id.txtginjalbawah);
		ginjalatas = (EditText) findViewById(R.id.txtginjalatas);
		dadabawah = (EditText) findViewById(R.id.txtdadabawah);
		dadaatas = (EditText) findViewById(R.id.txtdadaatas);
		parubawah = (EditText) findViewById(R.id.txtparubawah);
		paruatas = (EditText) findViewById(R.id.txtparuatas);
		
		setTextValue();
		
		//Button prev
		mNext	= (Button)findViewById(R.id.buttonnext);
		mNext.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				startActivity(new Intent(KnowledgeEditorActivity.this.getApplicationContext(), KnowledgeEditor2Activity.class));
			}
		});
		
		//Button close
		mclose	= (Button)findViewById(R.id.buttonclose);
		mclose.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				startActivity(new Intent(KnowledgeEditorActivity.this.getApplicationContext(), MainMenuActivity.class));
			}
		});
		
		//Button apply
		mapply	= (Button)findViewById(R.id.buttonapply);
		mapply.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				getTextValue();
				mesininferensi.setInferenceTable(TableField);
				mesininferensi.writeInferenceFile();
			}
		});
		
		//Button update
		mupdate	= (Button)findViewById(R.id.buttonupdate);
		mupdate.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				mesininferensi.serverUpdate();
			}
		});
		
		/*alert text for learning*/
		
		lbllaring	= (TextView)findViewById(R.id.lbllaring);
		lbllaring.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Laring"));
			}
		});
		
		lbltiroid	= (TextView)findViewById(R.id.lbltiroid);
		lbltiroid.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Tiroid"));
			}
		});
		
		lblbronkus	= (TextView)findViewById(R.id.lblbronkus);
		lblbronkus.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Bronkus"));
			}
		});
		
		lblappendiks	= (TextView)findViewById(R.id.lblappendiks);
		lblappendiks.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Appendix"));
			}
		});
		
		lblpankreas	= (TextView)findViewById(R.id.lblpankreas);
		lblpankreas.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Pankreas"));
			}
		});
		
		lblhati	= (TextView)findViewById(R.id.lblhati);
		lblhati.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Hati"));
			}
		});
		
		lblempedu	= (TextView)findViewById(R.id.lblempedu);
		lblempedu.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Empedu"));
			}
		});
		
		lblginjal	= (TextView)findViewById(R.id.lblginjal);
		lblginjal.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Ginjal"));
			}
		});
		
		lbldada	= (TextView)findViewById(R.id.lbldada);
		lbldada.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("RonggaDada"));
			}
		});
		

		lblparu	= (TextView)findViewById(R.id.lblparu);
		lblparu.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Paruparu"));
			}
		});
		
	}
	
	private void showmessagebox(String Message)
	{
		alertDialog.setMessage(Message);
		alertDialog.show();
		
	}
	
	private void setTextValue() {
		laringbawah.setText(TableField[1][0]);
		laringatas.setText(TableField[2][0]);
		tiroidbawah.setText(TableField[1][1]);
		tiroidatas.setText(TableField[2][1]);
		bronkusbawah.setText(TableField[1][2]);
		bronkusatas.setText(TableField[2][2]);
		appendiksbawah.setText(TableField[1][3]);
		appendiksatas.setText(TableField[2][3]);
		pankreasbawah.setText(TableField[1][4]);
		pankreasatas.setText(TableField[2][4]);
		hatibawah.setText(TableField[1][5]);
		hatiatas.setText(TableField[2][5]);
		empedubawah.setText(TableField[1][6]);
		empeduatas.setText(TableField[2][6]);
		ginjalbawah.setText(TableField[1][7]);
		ginjalatas.setText(TableField[2][7]);
		dadabawah.setText(TableField[1][8]);
		dadaatas.setText(TableField[2][8]);
		parubawah.setText(TableField[1][9]);
		paruatas.setText(TableField[2][9]);
	}

	private void getTextValue() {
		TableField[1][0] = laringbawah.getText().toString();
		TableField[2][0] = laringatas.getText().toString();
		TableField[1][1] = tiroidbawah.getText().toString();
		TableField[2][1] = tiroidatas.getText().toString();
		TableField[1][2] = bronkusbawah.getText().toString();
		TableField[2][2] = bronkusatas.getText().toString();
		TableField[1][3] = appendiksbawah.getText().toString();
		TableField[2][3] = appendiksatas.getText().toString();
		TableField[1][4] = pankreasbawah.getText().toString();
		TableField[2][4] = pankreasatas.getText().toString();
		TableField[1][5] = hatibawah.getText().toString();
		TableField[2][5] = hatiatas.getText().toString();
		TableField[1][6] = empedubawah.getText().toString();
		TableField[2][6] = empeduatas.getText().toString();
		TableField[1][7] = ginjalbawah.getText().toString();
		TableField[2][7] = ginjalatas.getText().toString();
		TableField[1][8] = dadabawah.getText().toString();
		TableField[2][8] = dadaatas.getText().toString();
		TableField[1][9] = parubawah.getText().toString();
		TableField[2][9] = paruatas.getText().toString();

	}
	AlertDialog alertDialog;
	ai.tubes.iris.knowledge.inferenceengine mesininferensi;
	String[][] TableField;
	private Button mNext,mclose,mapply,mupdate;
	private EditText laringbawah, laringatas, tiroidbawah, tiroidatas,	bronkusbawah, bronkusatas, appendiksbawah, appendiksatas,	pankreasbawah, pankreasatas, hatibawah, hatiatas, empedubawah,empeduatas, ginjalbawah, ginjalatas, dadabawah, dadaatas,	parubawah, paruatas;
	private TextView lbllaring, lbltiroid, lblbronkus, lblappendiks, lblpankreas, lblhati, lblempedu, lblginjal, lbldada, lblparu;
	
	
	
}
